package cn.virens.web.components.beetl.format;

import org.beetl.core.Format;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.StrUtil;
import cn.virens.database.common.BaseEnum;
import cn.virens.database.enums.UserType;

public class TypeFormat implements Format {

	@Override
	public Object format(Object data, String pattern) {
		if (StrUtil.equals(pattern, "user")) {
			return str(user(Convert.toInt(data)));
		} else {
			return "未知";
		}
	}

	private UserType user(Integer value) {
		return UserType.parse(value);
	}

	private static String str(BaseEnum<?> baseEnum) {
		if (baseEnum != null) {
			return baseEnum.getDesc();
		} else {
			return "未知";
		}
	}

}
